package com.glc.hms.system.controller.web;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.glc.hms.common.controller.BaseController;
import com.glc.hms.common.data.ResponseData;
import com.glc.hms.common.data.SuccessResponseData;
import com.glc.hms.common.page.PageFactory;
import com.glc.hms.common.page.PageVo;
import com.glc.hms.system.entity.SysLog;
import com.glc.hms.system.service.ISysLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author Santa
 * @since 2019/12/3
 */
@Slf4j
@Api(value = "日志", description = "日志接口", basePath = "/webApi/log")
@RestController
@RequestMapping("/webApi/log")
public class LogController extends BaseController {

    @Autowired
    private ISysLogService logService;

    @ApiOperation(value = "日志查询", response = ResponseData.class)
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public ResponseData getList(@ApiParam(name = "type", value = "日志类型", required = true) Integer type){
        Page page = PageFactory.defaultPage();
        QueryWrapper<SysLog> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("type",type);
        queryWrapper.orderByDesc("create_date");
        IPage result = logService.page(page,queryWrapper);
        PageVo pageInfo = PageFactory.createPageInfo(result);
        return new SuccessResponseData(pageInfo);
    }

    @ApiOperation(value = "访问量统计", response = ResponseData.class)
    @RequestMapping(value = "/getLogIp", method = RequestMethod.GET)
    public ResponseData getLogIp(){
        Map<String, Integer> res = logService.queryLoginNum();
        return new SuccessResponseData(res);
    }
}























